package com.yu8home.opcua.test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class SocketT {

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("===================服务器即将启动，等待客户端的连接===============");

        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        byte[] b = new byte[200];
        int len;
        while ((len = bufferedReader.read()) != -1) {
            System.out.println(new Date());
            String str = new String(b, 0, len);
            System.out.println("我是服务器端，客户端说：" + str);
        }


        System.out.println(new Date());
        System.out.println("=========连接成功==========");
    }

}
